home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Technotools
/
Technotools (Chestnut CD-ROM)(1993).ISO
/
lang_c
/
mc51bugs
/
q32837
< prev
next >
Wrap
Text File
|
1988-07-29
|
2KB
|
57 lines
Q32837 Bad Code Generated when Accessing Data in the Code Segment
C Compiler
5.10 | 5.10
MS-DOS | OS/2
Summary:
The C compiler generates incorrect code for a program that accesses
data in the code segment. It "forgets" that the data is in a far
segment and tries to access it with a near (16-bit) pointer.
A workaround to the problem is to compile with the optimizer
disabled (/Od).
Microsoft has confirmed this to be a problem in Version 5.10. We
are researching this problem and will post new information as it
becomes available.
More Information:
The following is the program that demonstrates the problem,
along with the generated code; it is compiled in medium model:
extern void far SomeProc();
main()
{
typedef struct {
char patch;
} TEMPLATE;
TEMPLATE far *lpSomeProc;
lpSomeProc = (TEMPLATE far *)SomeProc; /* point pointer into code segment*/
lpSomeProc->patch = 123; /* Bad code generated for this statement */
} /* when optimizer used */
/*
;BAD CODE:
; Line 11
mov WORD PTR [bp-4],OFFSET _SomeProc ;lpSomeProc
mov WORD PTR [bp-2],SEG _SomeProc
; Line 12
mov BYTE PTR _SomeProc,123 <== THIS IS INCORRECT; A NEAR PTR
;GOOD CODE: (produced with -Od option)
; Line 11
mov WORD PTR [bp-4],OFFSET _SomeProc ;lpSomeProc
mov WORD PTR [bp-2],SEG _SomeProc
; Line 12
les bx,DWORD PTR [bp-4] ;lpSomeProc
mov BYTE PTR es:[bx],123 <== THIS IS CORRECT; A FAR PTR
; Line 13
*/
Keywords: buglist5.10 tar78670
Updated 88/07/29 12:16